import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CcolorRadioGroup extends StatelessWidget {
  final List<Color> values;
  final Color groupValue;
  final ValueChanged<Color> onChanged;

  const CcolorRadioGroup({
    Key? key,
    required this.values,
    required this.groupValue,
    required this.onChanged,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Wrap(
      spacing: 42.w,
      children: List.generate(
        values.length,
        (index) => _buildRadioItem(values[index]),
      ),
    );
  }

  Widget _buildRadioItem(Color value) {
    final isSelected = value == groupValue;

    return GestureDetector(
      onTap: () => onChanged(value),
      child: Container(
        height: 22.w,
        width: 22.w,
        decoration: BoxDecoration(
          color: value,
          border: value == Color(0XFFFFFFFF)
              ? Border.all(color: Color(0xFFC1C1C1))
              : null,
          borderRadius: BorderRadius.circular(
              50.w), // Changed to make the corners more rounded
        ),
        child: Center(
          child: Icon(
            Icons.check,
            size: 14.w,
            color: isSelected
                ? (value == Color(0XFFFFFFFF) ? Colors.black : Colors.white)
                : Colors.transparent,
          ),
        ),
      ),
    );
  }
}
